#ifndef IOT_SWITCH_MAINWINDOW_H
#define IOT_SWITCH_MAINWINDOW_H

#include <QMainWindow>
#include <QPushButton>
#include "qmqtt.h"
#include <QtDebug>
#include <QMessageBox>
#include <QKeyEvent>
#include <iostream>
#include <QSystemTrayIcon>

using namespace std;

QT_BEGIN_NAMESPACE
namespace Ui { class iot_switch_mainWindow; }
QT_END_NAMESPACE

class iot_switch_mainWindow : public QMainWindow
{
    Q_OBJECT

public:
    iot_switch_mainWindow(QWidget *parent = nullptr);
    ~iot_switch_mainWindow();

private slots:
    void clickSwitch();
    void connectError(const QMQTT::ClientError error);
    void connected();
    void disconnected();
    void published(const QMQTT::Message& message, quint16);

    void showWindows();
    void closeWindows();
    void activatedSystemTrayIcon(QSystemTrayIcon::ActivationReason reason);

private:
    Ui::iot_switch_mainWindow *ui;
    QPushButton* pBtnArray[4];//按钮
    int switchStatus[4];//开关状态1开0关

    QMQTT::Client *client;//MQTT客户端实例
    quint16 pubCount;//MQTT发布次数

    void keyPressEvent(QKeyEvent * event) override;
    void keyReleaseEvent(QKeyEvent * event) override;

    void publishMsg();
    int getSwitchStatus(QPushButton *button);//通过button的text获取开关状态

    QSystemTrayIcon *m_systemTray;
    QMenu *m_menu;
    bool qMenuBug;
    QAction *m_action1;
    QAction *m_action2;
    bool isHide;

};
#endif // IOT_SWITCH_MAINWINDOW_H
